package db

import (
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
	"log"
)

var Db, _ = Mysql()

func Mysql() (*sql.DB, error) {
	db, err := sql.Open("mysql", "root:12345678@tcp(localhost:3306)/bms")
	if err != nil {
		log.Println("数据库链接失败")
		return nil, err
	}
	db.Ping()
	//defer func() {
	//	if db != nil {
	//		db.Close()
	//	}
	//}()
	return db, nil
}
